package tour.spring.bc.bo.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import tour.spring.bc.dao.ClientDao;
import tour.spring.bc.dao.ReservationDao;
import tour.spring.bc.dao.TourDao;
import tour.spring.bc.model.Client;
import tour.spring.bc.model.Reservation;
import tour.spring.bc.model.Tour;

@Service
public class ReservationBoImpl {

	@Autowired
	ReservationDao reservationDao;
	
	@Autowired
	TourDao tourDao;
	
	@Autowired
	ClientDao clientDao;
	
	@Transactional
	public void saveReservation(long tourId, String clientLogin, int participantQuantity){
		Tour tour = tourDao.load(tourId);
		Client client = clientDao.getClientByLogin(clientLogin);
		
		Reservation reservation = new Reservation();
		reservation.setParticipantQuantity(participantQuantity);
		reservation.setTour(tour);
		reservation.setClient(client);
		
		reservationDao.save(reservation);
	}
	
}
